package com.lmt.config.load;

import com.lmt.common.util.ResultUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.core.io.support.PropertiesLoaderUtils;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Properties;

/**
 * @author MT-Lin
 */
@Slf4j
@Order(1)
@Component
public class LoadErrorMessage implements ApplicationRunner {

    @Override
    public void run(ApplicationArguments args) throws Exception {
        try {
            log.info("begin load errorMessage.properties.");
            Properties properties = PropertiesLoaderUtils.loadAllProperties("errorMessage.properties");
            for (Object key : properties.keySet()) {
                String keyStr = key.toString();
                ResultUtil.getErrorMessageMap().put(keyStr, properties.getProperty(keyStr));
            }
            log.info("load errorMessage.properties finish.");
        } catch (IOException e) {
            log.error("load errorMessage.properties fail");
            throw e;
        }
    }
}
